package com.oracle.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oracle.beans.CheckItem;
import com.oracle.beans.PageBean;
import com.oracle.beans.QueryPageVo;
import com.oracle.beans.ResultInfo;
import com.oracle.dao.CheckItemMapper;
import com.oracle.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    CheckItemMapper checkItemMapper;
    @Override
    public PageBean<CheckItem> findList(QueryPageVo vo) {
        Page<CheckItem> page = PageHelper.startPage(vo.getCurrentPage(),vo.getPageSize());
        checkItemMapper.findList(vo);

        PageBean<CheckItem> pageBean = new PageBean<>();
        pageBean.setList(page.getResult());
        pageBean.setTotalCount(page.getTotal());
        pageBean.setTotalPage(page.getPages());
        pageBean.setCurrentPage(vo.getCurrentPage());
        pageBean.setPageSize(vo.getPageSize());
        return pageBean;
    }

    @Override
    public ResultInfo add(CheckItem checkItem) {
        Integer rows=checkItemMapper.add(checkItem);
        if(rows>0){
            return new ResultInfo(true,"添加检查项成功",null);
        }else {
            return new ResultInfo(false,"添加检查项失败",null);
        }
    }

    @Override
    public ResultInfo update(CheckItem checkItem) {
        Integer rows=checkItemMapper.update(checkItem);
        if(rows>0){
            return new ResultInfo(true,"修改检查项成功",null);
        }else{
            return new ResultInfo(false,"修改检查项失败",null);
        }
    }

    @Override
    public ResultInfo dalete(Integer id) {
        Integer rows=checkItemMapper.dalete(id);
        if(rows>0){
            return new ResultInfo(true,"删除检查项成功",null);
        }else{
            return new ResultInfo(false,"删除检查项失败",null);
        }
    }

    @Override
    public ResultInfo findAll() {
        List<CheckItem> checkItems=checkItemMapper.findList(new QueryPageVo());
        return new ResultInfo(true,"",checkItems);
    }
}
